#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Jimin Huang <huangjimin@whu.edu.cn>
# Date: 02.02.2017
"""Spider class
"""
import arrow
import logging

from scrapy_redis.spiders import RedisSpider

from aquila.items import AquilaItem


LOGGER = logging.getLogger(__name__)


class Aquila(RedisSpider):
    """Class of the spider inherit ``RedisSpider``
    """
    name = "aquila"
    redis_key = "queue:url"

    def parse(self, response):
        """Parse the response and yield more requests

        Args:
            response: ``scrapy.Response``

        Return:
            a generator of ``AquilaItem`` and ``scrapy.Request``
        """
        body = response.body.decode(response.encoding)
        yield AquilaItem(
            url=response.url, text=body, time=arrow.utcnow().datetime
        )
